/* =====================================================================================
/   TABLE: [BlogCategories]
/  ===================================================================================== */

if exists (select * from [dbo].sysobjects where id = object_id(N'[dbo].[BlogCategories]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[BlogCategories]

GO

CREATE TABLE [dbo].[BlogCategories](
	[Id] [uniqueidentifier] ROWGUIDCOL  NOT NULL CONSTRAINT [DF_BlogCategories_Id]  DEFAULT (newid()),
	[PageId] [uniqueidentifier] NOT NULL,
	[CategoryName] [nvarchar](50) NOT NULL,--MUST BE UNIQUE
	[Description] [nvarchar](200) NULL,
	[ParentId] [uniqueidentifier] NULL,
	[CreatedDate] [datetime] NOT NULL,
	[ModifiedDate] [datetime] NOT NULL,
	[Slug] [nvarchar](255) NULL,
 CONSTRAINT [PK_BlogCategories] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

--ALTER TABLE [dbo].[BlogCategories]  WITH CHECK ADD  CONSTRAINT [FK_BlogCategories_Pages] FOREIGN KEY([PageId])
--REFERENCES [dbo].[Pages] ([PageId])
--GO
--ALTER TABLE [dbo].[BlogCategories] CHECK CONSTRAINT [FK_BlogCategories_Pages]
--GO

/* =====================================================================================
/   TABLE: [BlogPosts]
/  ===================================================================================== */

if exists (select * from [dbo].sysobjects where id = object_id(N'[dbo].[BlogPosts]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[BlogPosts]

GO

CREATE TABLE [dbo].[BlogPosts](
	[Id] [uniqueidentifier] ROWGUIDCOL  NOT NULL CONSTRAINT [DF_BlogPosts_Id]  DEFAULT (newid()),
	[PageId] [uniqueidentifier] NOT NULL,
	[Title] [nvarchar](255) NOT NULL,
	[Description] [nvarchar](max) NULL,
	[Keywords] [nvarchar](max) NULL,
	[PostContent] [nvarchar](max) NOT NULL,
	[CreatedDate] [datetime] NOT NULL,
	[ModifiedDate] [datetime] NOT NULL,
	[Author] [nvarchar](50) NOT NULL,
	[IsPublished] [bit] NOT NULL,
	[IsCommentEnabled] [bit] NOT NULL,
	[Rating] [int] NOT NULL,
	[Slug] [nvarchar](255) NULL,
 CONSTRAINT [PK_BlogPosts] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

--ALTER TABLE [dbo].[BlogPosts]  WITH CHECK ADD  CONSTRAINT [FK_BlogPosts_Pages] FOREIGN KEY([PageId])
--REFERENCES [dbo].[Pages] ([PageId])
--GO
--ALTER TABLE [dbo].[BlogPosts] CHECK CONSTRAINT [FK_BlogPosts_Pages]
--GO

/* =====================================================================================
/   TABLE: [BlogPostCategory]
/  ===================================================================================== */

if exists (select * from [dbo].sysobjects where id = object_id(N'[dbo].[BlogPostCategory]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[BlogPostCategory]

GO

CREATE TABLE [dbo].[BlogPostCategory](
	[Id] [uniqueidentifier] ROWGUIDCOL  NOT NULL CONSTRAINT [DF_BlogPostCategory_Id]  DEFAULT (newid()),
	[PostId] [uniqueidentifier] NOT NULL,
	[CategoryId] [uniqueidentifier] NOT NULL,
	[CreatedDate] [datetime] NOT NULL,
	[ModifiedDate] [datetime] NOT NULL,
 CONSTRAINT [PK_BlogPostCategory] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[BlogPostCategory]  WITH CHECK ADD  CONSTRAINT [FK_BlogPostCategory_BlogCategories] FOREIGN KEY([CategoryId])
REFERENCES [dbo].[BlogCategories] ([Id])
GO
ALTER TABLE [dbo].[BlogPostCategory] CHECK CONSTRAINT [FK_BlogPostCategory_BlogCategories]
GO
ALTER TABLE [dbo].[BlogPostCategory]  WITH CHECK ADD  CONSTRAINT [FK_BlogPostCategory_BlogPosts] FOREIGN KEY([PostId])
REFERENCES [dbo].[BlogPosts] ([Id])
GO
ALTER TABLE [dbo].[BlogPostCategory] CHECK CONSTRAINT [FK_BlogPostCategory_BlogPosts]
GO


/* =====================================================================================
/   TABLE: [BlogPostComment]
/  ===================================================================================== */

if exists (select * from [dbo].sysobjects where id = object_id(N'[dbo].[BlogPostComment]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[BlogPostComment]

GO

CREATE TABLE [dbo].[BlogPostComment](
	[Id] [uniqueidentifier] ROWGUIDCOL  NOT NULL CONSTRAINT [DF_BlogPostComment_Id]  DEFAULT (newid()),
	[PostId] [uniqueidentifier] NOT NULL,
	[ParentCommentId] [uniqueidentifier] NULL,
	[CreatedDate] [datetime] NOT NULL,
	[ModifiedDate] [datetime] NOT NULL,
	[Author] [nvarchar](255) NOT NULL,
	[Email] [nvarchar](255) NOT NULL,
	[Website] [nvarchar](255) NULL,
	[Comment] [nvarchar](max) NOT NULL,
	[Country] [nvarchar](255) NULL,
	[Ip] [nvarchar](50) NOT NULL,
	[IsApproved] [bit] NOT NULL,
 CONSTRAINT [PK_BlogPostComment] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
ALTER TABLE [dbo].[BlogPostComment]  WITH CHECK ADD  CONSTRAINT [FK_BlogPostComment_BlogPosts] FOREIGN KEY([PostId])
REFERENCES [dbo].[BlogPosts] ([Id])
GO
ALTER TABLE [dbo].[BlogPostComment] CHECK CONSTRAINT [FK_BlogPostComment_BlogPosts]
GO



/* =====================================================================================
/   TABLE: [BlogPostNotify]
/  ===================================================================================== */

if exists (select * from [dbo].sysobjects where id = object_id(N'[dbo].[BlogPostNotify]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[BlogPostNotify]

GO

CREATE TABLE [dbo].[BlogPostNotify](
	[Id] [uniqueidentifier] ROWGUIDCOL  NOT NULL CONSTRAINT [DF_BlogPostNotify_Id]  DEFAULT (newid()),
	[PostId] [uniqueidentifier] NOT NULL,
	[NotifyAddress] [nvarchar](255) NOT NULL,
	[CreatedDate] [datetime] NOT NULL,
	[ModifiedDate] [datetime] NOT NULL,
 CONSTRAINT [PK_BlogPostNotify] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
ALTER TABLE [dbo].[BlogPostNotify]  WITH CHECK ADD  CONSTRAINT [FK_BlogPostNotify_BlogPosts] FOREIGN KEY([PostId])
REFERENCES [dbo].[BlogPosts] ([Id])
GO
ALTER TABLE [dbo].[BlogPostNotify] CHECK CONSTRAINT [FK_BlogPostNotify_BlogPosts]
GO

/* =====================================================================================
/   TABLE: [BlogPostTag]
/  ===================================================================================== */

if exists (select * from [dbo].sysobjects where id = object_id(N'[dbo].[BlogPostTag]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[BlogPostTag]

GO

CREATE TABLE [dbo].[BlogPostTag](
	[Id] [uniqueidentifier] ROWGUIDCOL  NOT NULL CONSTRAINT [DF_BlogPostTag_Id]  DEFAULT (newid()),
	[PageId] [uniqueidentifier] NOT NULL,
	[PostId] [uniqueidentifier] NOT NULL,
	[Tag] [nvarchar](50) NOT NULL,
	[CreatedDate] [datetime] NOT NULL,
	[ModifiedDate] [datetime] NOT NULL,
 CONSTRAINT [PK_BlogPostTag] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
ALTER TABLE [dbo].[BlogPostTag]  WITH CHECK ADD  CONSTRAINT [FK_BlogPostTag_BlogPosts] FOREIGN KEY([PostId])
REFERENCES [dbo].[BlogPosts] ([Id])
GO
ALTER TABLE [dbo].[BlogPostTag] CHECK CONSTRAINT [FK_BlogPostTag_BlogPosts]

GO

--ALTER TABLE [dbo].[BlogPostTag]  WITH CHECK ADD  CONSTRAINT [FK_BlogPostTag_Pages] FOREIGN KEY([PageId])
--REFERENCES [dbo].[Pages] ([PageId])
--GO
--ALTER TABLE [dbo].[BlogPostTag] CHECK CONSTRAINT [FK_BlogPostTag_Pages]
--GO